# -*- coding: utf-8 -*-
from typing import Sequence

from sqlalchemy import Select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy_crud_plus import CRUDPlus

# 动态导入模型和Schema
from App.app.admin.models.sys_config import SysConfig
from App.app.admin.schemas.sys_config_schema import (
    CreateSysConfigParam,
    UpdateSysConfigParam
)


class CRUDSysConfig(CRUDPlus[SysConfig]):
    async def get(self, db: AsyncSession) -> SysConfig | None:
        """
        获取平台配置

        :param db:
        :return:
        """
        query = await self.select_models(db)
        return query[0] if query else None

    async def update(self, db: AsyncSession, pk: int, obj_in: UpdateSysConfigParam) -> int:
        """
        更新平台配置

        :param pk:
        :param db:
        :param obj_in:
        :return:
        """
        return await self.update_model(db, pk, obj_in)

    async def create(self, db: AsyncSession, obj_in: CreateSysConfigParam) -> SysConfig:
        """
        新增平台配置
        :param db:
        :param obj_in:
        :return:
        """
        return await self.create_model(db, obj_in)


SysConfigDao: CRUDSysConfig = CRUDSysConfig(SysConfig)
